//
// Created by DELL on 2024/2/29.
//
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <utility>

int main(int count, const char* args[])
{
    int nums[]{12, 4, -18, 50, 3, 9, 88};
    int numCount = sizeof(nums)/sizeof(int);

    std::cout << "--------------- Priority Queue -------------" << std::endl;
    {
        std::priority_queue<int, std::vector<int>, std::greater<>> priorityQueue;
        for (auto num : nums)
        {
            priorityQueue.push(num);
        }
        for (int i = 0; i < numCount; ++i)
        {
            std::cout << priorityQueue.top() << ", ";
            priorityQueue.pop();
        }
        std::cout << std::endl;
    }

    std::cout << "--------------- Heap -------------" << std::endl;
    {
        std::vector<int> vector(std::cbegin(nums), std::cend(nums));
        auto pred =  [](int l, int r) { return l > r; };

//        vector.clear();
//        for (int i = 0; i < numCount; ++i)
//        {
//            vector.push_back(nums[i]);
//            std::push_heap(vector.begin(), vector.end(), pred);
//        }

        std::make_heap(vector.begin(), vector.end(), pred);
        for (int i = 0; i < numCount; ++i)
        {
            std::pop_heap(vector.begin(), vector.end(), pred);
            std::cout << vector.back() << ", ";
            vector.pop_back();
        }

    }


    return 0;
}